package com.kevin.designpattern.interpreter;

public class Plus extends AbstractExpression {

    // 声明加号左边的表达式
    private AbstractExpression left;
    // 声明加号右边的表达式
    private AbstractExpression right;

    public Plus(AbstractExpression left, AbstractExpression right) {
        this.left = left;
        this.right = right;
    }

    @Override
    public int interpret(Context context) {

        // 将加法的左边和右边进行相加  2 + 3
        return left.interpret(context) + right.interpret(context);

    }

    @Override
    public String toString() {
        return "Plus{" +
                "left=" + left +
                ", right=" + right +
                '}';
    }
}
